<?php

namespace app\admin\model\old\order;

use think\Model;
use traits\model\SoftDelete;

class Aftersale extends Model
{

    use SoftDelete;

    

    // 表名
    protected $table = 'old_order_aftersale';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'type_text',
        'refund_status_text'
    ];
    

    
    public function getTypeList()
    {
        return ['refund' => __('Type refund'), 'return' => __('Type return'), 'other' => __('Type other')];
    }
    const REFUND_STATUS_F_1 = '-1';
    const REFUND_STATUS_0 = '0';
    const REFUND_STATUS_1 = '1';


    public function getRefundStatusList()
    {
        return ['-1' => __('Refund_status -1'), '0' => __('Refund_status 0'), '1' => __('Refund_status 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRefundStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refund_status']) ? $data['refund_status'] : '');
        $list = $this->getRefundStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public static function getSn($user_id)
    {
        $rand = $user_id < 9999 ? mt_rand(100000, 99999999) : mt_rand(100, 99999);
        $order_sn = date('Yhis') . $rand;

        $id = str_pad($user_id, (24 - strlen($order_sn)), '0', STR_PAD_BOTH);

        return 'OA' . $order_sn . $id;
    }



}
